package academic.ui.client.view;

import ui.client.GenericContainerTag;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.gwtplatform.mvp.client.ViewImpl;

public class ModalView extends ViewImpl {

	GenericContainerTag backgroundGlass = new GenericContainerTag("div");
	Image img = new Image(GWT.getModuleBaseURL()+"images/whiteModal.png");
	
	public ModalView() {
		backgroundGlass.setStyleName("backGroundGlass");
		positionBackground();
	}
	
	@Override
	public Widget asWidget() {
		return backgroundGlass;
	}
	
	protected void positionBackground() {
		RootPanel.get().add(backgroundGlass);
		DOM.setStyleAttribute(backgroundGlass.getElement(), "height", String.valueOf(RootPanel.get().getOffsetHeight())+"px");
		DOM.setStyleAttribute(backgroundGlass.getElement(), "width", String.valueOf(Window.getClientWidth())+"px");
		
		
	}
	
	protected void positionDialog(Widget dialog, int width, int height) {
		DOM.setStyleAttribute(dialog.getElement(), "left", String.valueOf(Math.max(1,(Window.getClientWidth()-width)/2))+"px");
		DOM.setStyleAttribute(dialog.getElement(),"top",height+"px");
		
		
		img.setStyleName("loginImage");
		RootPanel.get().add(img);
		DOM.setStyleAttribute(img.getElement(), "left", String.valueOf(Math.max(1,(Window.getClientWidth()-width)/2))+"px");
		DOM.setStyleAttribute(img.getElement(),"top",String.valueOf(Math.max(1,(Window.getClientHeight()+Window.getScrollTop()-height)/2))+"px");
		
	}

	protected void hide() {
		RootPanel.get().remove(backgroundGlass);
		RootPanel.get().remove(img);
	}
}
